package com.douqu.game.core.entity.world;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.factory.DataFactory;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-02-06 10:54
 */
public class WorldRankBean {

    private String objectIndex;

    private long value;

    /**
     * 单位:秒
     */
    private int createTime;

    /**
     * 单位:秒
     */
    private int lastUpdateTime;

    public WorldRankBean() {
    }

    public WorldRankBean(String objectIndex){
        this.objectIndex = objectIndex;
    }

    public WorldRankBean(String objectIndex, long value) {
        this.objectIndex = objectIndex;
        this.value = value;
        this.createTime = (int) (DataFactory.currentTime/1000);
        this.lastUpdateTime = createTime;
    }

    public void writeTo(ByteBuffer buffer)
    {
        buffer.writeUTF(objectIndex);
        buffer.writeLong(value);
        buffer.writeInt(createTime);
        buffer.writeInt(lastUpdateTime);
    }

    public void loadFrom(ByteBuffer buffer)
    {
        objectIndex = buffer.readUTF();
        //***************旧的
//        value = buffer.readInt();
        //********************
        //----------------新的
        value = buffer.readLong();
        //----------------
        createTime = buffer.readInt();
        lastUpdateTime = buffer.readInt();
    }

    public int getCreateTime() {
        return createTime;
    }

    public void setCreateTime(int createTime) {
        this.createTime = createTime;
    }




    public String getObjectIndex() {
        return objectIndex;
    }

    public void setObjectIndex(String objectIndex) {
        this.objectIndex = objectIndex;
    }

    public long getValue() {
        return value;
    }

    public void setValue(long value) {
        this.value = value;
    }

    public int getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(int lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public void addValue(long val){
        value += val;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof WorldRankBean)) return false;

        WorldRankBean that = (WorldRankBean) o;

        if (!objectIndex.equals(that.objectIndex)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return objectIndex == null ? 0 : objectIndex.hashCode();
    }
}
